package com.hskn.hss.module.tlresplan.controller;


import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.domain.BaseEntity;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.tlcompany.entity.TlCompany;
import com.hskn.hss.module.tlposition.mapper.TlPositionMapper;
import com.hskn.hss.module.tlresplan.entity.TlEmergentResplan;
import com.hskn.hss.module.tlresplan.mapper.TlEmergentResplanMapper;
import com.hskn.hss.module.tlresplan.service.ITlEmergentResplanService;
import com.hskn.hss.module.tlresplan.vo.TlEmergentResPlanVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-18
 */
@Api(tags = {"-tl_emergentres_plan"}, description = "应急预案")
@Slf4j
@RestController
@RequestMapping("/hss/tlresplan")
public class TlEmergentResplanController {

    @Autowired
    ITlEmergentResplanService tlEmergentResplanService;

    @SysLog(businessType = BusinessType.INSERT, tableName = "tl_emergent_resplan", bean = TlEmergentResplan.class, beanMapper = TlEmergentResplanMapper.class, names = "resplanname")
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public AjaxResult<Object> insert(@RequestBody @Validated TlEmergentResplan tlEmergentResplan, HttpServletRequest request) {
        try {
            return tlEmergentResplanService.insert(tlEmergentResplan);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "tl_emergent_resplan", idKey = "id", bean = TlEmergentResplan.class, beanMapper = TlEmergentResplanMapper.class, names = "resplanname")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(@RequestBody @Validated TlEmergentResplan tlEmergentResplan, HttpServletRequest request) {
        try {
            return tlEmergentResplanService.update(tlEmergentResplan);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.DELETE, tableName = "tl_emergent_resplan", idKey = "id", bean = TlEmergentResplan.class, beanMapper = TlEmergentResplanMapper.class, names = "resplanname")
    @RequestMapping(value = "deletebyid", method = RequestMethod.POST)
    public AjaxResult<Object> deletebyid(@RequestBody @Validated TlEmergentResplan tlEmergentResplan) {
        try {
            return tlEmergentResplanService.deletebyid(tlEmergentResplan);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("删除失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.DELETE, tableName = "tl_emergent_resplan", idKey = "ids", bean = TlEmergentResplan.class, beanMapper = TlEmergentResplanMapper.class, names = "resplanname")
    @ApiOperation(value = "批量删除接口", notes = "批量删除")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = TlEmergentResplan.class)
    })
    @RequestMapping(value = "deletebatchbyid", method = RequestMethod.POST)
    public AjaxResult<Object> deletebatchbyid(@RequestBody @Validated TlEmergentResplan tlEmergentResplan,HttpServletRequest request) {
        try {
            return tlEmergentResplanService.deletebatchbyid(tlEmergentResplan);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("删除失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "tl_emergent_resplan", idKey = "ids", bean = TlEmergentResplan.class, beanMapper = TlEmergentResplanMapper.class, names = "resplanname")
    @ApiOperation(value = "批量禁用恢复接口", notes = "批量禁用恢复")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = TlEmergentResplan.class)
    })
    @RequestMapping(value = "changeStatus", method = RequestMethod.POST)
    public AjaxResult<Object> changeStatus(@RequestBody @Validated TlEmergentResplan tlEmergentResplan,HttpServletRequest request) {

        try {
            return tlEmergentResplanService.changeStatus(tlEmergentResplan);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("修改失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getSelectList", method = RequestMethod.POST)
    public AjaxResult<Object> getSelectList(@RequestBody @Validated TlEmergentResplan tlEmergentResplan) {
        return AjaxResult.success(tlEmergentResplanService.getSelectList(tlEmergentResplan));
    }

    @RequestMapping(value = "getDetail", method = RequestMethod.POST)
    public AjaxResult<Object> getDetail(@RequestBody @Validated TlEmergentResplan tlEmergentResplan) {

        try {
            tlEmergentResplan = tlEmergentResplanService.getDetail(tlEmergentResplan);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
        return AjaxResult.success(tlEmergentResplan);

    }

    @RequestMapping(value = "getList", method = RequestMethod.POST)
    public AjaxResult<Object> getList(@RequestBody @Validated TlEmergentResplan tlEmergentResplan) {
        try {
            BaseEntity entity = new BaseEntity();
            TlEmergentResPlanVO resultList = tlEmergentResplanService.getList(entity, tlEmergentResplan);
            return AjaxResult.success(resultList);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }


    @RequestMapping(value = "emergentPlanCalendar", method = RequestMethod.POST)
    public AjaxResult<Object> emergentPlanCalendar() {
        try {
            return AjaxResult.success(tlEmergentResplanService.emergentPlanCalendar());
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }
}

